package com.ruoyi.brs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.bms.domain.BmsBooks;
import com.ruoyi.bms.domain.BmsUserUpload;
import com.ruoyi.bms.service.IBmsUserUploadService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.brs.domain.BrsUser;
import com.ruoyi.brs.service.IBrsUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理租赁用户信息Controller
 * 
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/brs/user")
public class BrsUserController extends BaseController
{
    @Autowired
    private IBrsUserService brsUserService;
    @Autowired
    private IBmsUserUploadService brsUserUploadService;


    /**
     * 查询管理租赁用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('brs:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(BrsUser brsUser)
    {
        startPage();
        List<BrsUser> list = brsUserService.selectBrsUserList(brsUser);
        return getDataTable(list);
    }

    /**
     * 导出管理租赁用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('brs:user:export')")
    @Log(title = "管理租赁用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BrsUser brsUser)
    {
        List<BrsUser> list = brsUserService.selectBrsUserList(brsUser);
        ExcelUtil<BrsUser> util = new ExcelUtil<BrsUser>(BrsUser.class);
        util.exportExcel(response, list, "管理租赁用户信息数据");
    }

    /**
     * 获取管理租赁用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('brs:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(brsUserService.selectBrsUserById(id));
    }

    /**
     * 新增管理租赁用户信息
     */
    @PreAuthorize("@ss.hasPermi('brs:user:add')")
    @Log(title = "管理租赁用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BrsUser brsUser)
    {
        return toAjax(brsUserService.insertBrsUser(brsUser));
    }

    /**
     * 注册租赁用户信息
     */
    @Log(title = "注册租赁用户信息", businessType = BusinessType.INSERT)
    @GetMapping("/faddUser")
    public AjaxResult faddUser()
    {
        return toAjax(brsUserService.insertfBrsUser());
    }



    /**
     * 修改管理租赁用户信息
     */
    @PreAuthorize("@ss.hasPermi('brs:user:edit')")
    @Log(title = "管理租赁用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BrsUser brsUser)
    {
        return toAjax(brsUserService.updateBrsUser(brsUser));
    }

    /**
     * 删除管理租赁用户信息
     */
    @PreAuthorize("@ss.hasPermi('brs:user:remove')")
    @Log(title = "管理租赁用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(brsUserService.deleteBrsUserByIds(ids));
    }



    @Log(title = "用户借阅", businessType = BusinessType.INSERT)
    @PostMapping("/Userlease/{bookId}")
    public AjaxResult Userlease(@PathVariable Long bookId) {
        return brsUserService.Userlease(bookId);
    }


    @Log(title = "借阅pdf", businessType = BusinessType.INSERT)
    @GetMapping("/Userlease/getLeaseBooksInfo/{bookId}")
    public AjaxResult getLeaseBooksInfo(@PathVariable Long bookId) {
        return brsUserService.getLeaseBooksInfo(bookId);
    }


    /**
     * 修改用户上传管理
     */
    @Log(title = "用户上传管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updata")
    public AjaxResult edit(@RequestBody BmsUserUpload bmsUserUpload)
    {
        return toAjax(brsUserService.updateBrsUserUpload(bmsUserUpload));
    }



    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo() {
        return brsUserService.getUserInfo();
    }







}
